package cn.xp.service.impl;

import cn.xp.domain.Floor;
import cn.xp.dto.DeviceTypeDto;
import cn.xp.dto.FloorDeviceDto;
import cn.xp.dto.FloorDto;
import cn.xp.fegin.DeviceFeignClient;
import cn.xp.mapper.FloorMapper;
import cn.xp.service.IFloorService;
import cn.xp.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FloorServiceImpl implements IFloorService {

    @Autowired
    private FloorMapper floorMapper;

    @Autowired
    private DeviceFeignClient deviceFeignClient;
    @Override
    public JSONResult<Floor> floorAdd(Floor floor) {
        System.out.println(floor);
        floorMapper.floorAdd(floor);
        return JSONResult.success();
    }

    @Override
    public List<FloorDto> floorList(Long id) {
        List<Floor> floorList = floorMapper.getBuildId(id);
        List<FloorDto> arrayList = new ArrayList<>();
        for (Floor floor : floorList) {
            FloorDto floorDto = new FloorDto();
            floorDto.setName(floor.getName());
            List<DeviceTypeDto> deviceTypeDtos = deviceFeignClient.DeviceType(id);
            floorDto.setDeviceList(deviceTypeDtos);
            arrayList.add(floorDto);
        }
        return arrayList;
    }

    @Override
    public List<FloorDeviceDto> floorType(Long id) {
        List<Floor> floorList = floorMapper.getBuildId(id);
        List<FloorDeviceDto> arrayList = new ArrayList<>();
        for (Floor floor : floorList) {
            FloorDeviceDto floorDeviceDto = new FloorDeviceDto();
            floorDeviceDto.setName(floor.getName());
            List<DeviceTypeDto> deviceTypeDtos = deviceFeignClient.TypeList(id);
            floorDeviceDto.setDevice(deviceTypeDtos);
            arrayList.add(floorDeviceDto);
        }
        return arrayList;
    }
}
